import 'package:flutter/material.dart';
import 'package:flutter_mode/utils.dart';
import 'package:flutter_mode/zjw/data_transfer/CountModel.dart';
import 'package:flutter_mode/zjw/data_transfer/ScopedUnderScreen.dart';
import 'package:scoped_model/scoped_model.dart';

class ScopedTopScreen extends StatefulWidget {
  @override
  _ScopedTopScreenState createState() => new _ScopedTopScreenState();
}

class _ScopedTopScreenState extends State<ScopedTopScreen> {
  Model getModel(BuildContext context) {
    //直接使用of
    final countModel = ScopedModel.of<CountModel>(context);
    //使用CountModel中重写的of
    final countModel2 = CountModel().of(context);

    countModel.increment();
    countModel2.increment();
    return countModel;
    //    return countMode2;
  }

  @override
  Widget build(BuildContext context) {
    return ScopedModelDescendant<CountModel>(builder: (context, child, model) {
      return new Scaffold(
        appBar: new AppBar(
          title: new Text('ScopedTopScreen'),
        ),
        body: Center(
          child: Text(
            model.count.toString(),
            style: TextStyle(fontSize: 48),
          ),
        ),
        floatingActionButton: FloatingActionButton(
            onPressed: () =>
                pushMaterial(context, ScopedUnderScreen(title: 'ScopedUnderScreen')),
            child: Icon(Icons.forward)),
      );
    });
  }
}
